# -*- coding: UTF-8 -*-
import os
import json,chardet,time
from flask_cors import *
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
from flask import Flask,request,make_response
app = Flask(__name__)
index=0
 
@app.route('/index1', methods=[ 'POST'])
def getcontent():  
    global index
    content=readFile('./data/resp')
    print(content)
    rst = make_response(json.loads(content))
    # setHeader(rst)
    return rst,200

@app.route('/index2', methods=[ 'POST'])
def index2():  
    global index
    content=readFile('./data/委托中')
    print(content)
    rst = make_response(json.loads(content))
    # setHeader(rst)
    return rst,200

@app.route('/index3', methods=[ 'POST'])
def index3():  
    global index
    content=readFile('./data/resp3')
    print(content)
    rst = make_response(json.loads(content))
    # setHeader(rst)
    return rst,200
@app.route('/index4', methods=[ 'POST'])
def index4():  
    global index
    content=readFile('./data/取消委托')
    print(content)
    rst = make_response(json.loads(content))
    # setHeader(rst)
    return rst,200
    
    
@app.route('/cargoDetail', methods=[ 'POST'])
def cargoDetail():  
    global index
    content=readFile('./data/cargoDetail')
    print(content)
    rst = make_response(json.loads(content))
    # setHeader(rst)
    return rst,200


def readFile(fileName="test.txt"):
    with open(fileName,"rb") as f:
        data=f.read()
        strType=chardet.detect(data)
        print(strType)
        realData=data.decode(strType['encoding'])
        return realData

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5510)
    # setHeader(None)